﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace VirtuOS.Components.Commands
{
    class list
    {
        public static string help = "Lists the available commands.";
        public static string register_name = "cmdlist";
        public static List<string> clist = new List<string>();
        public static bool requires_root = false;

        public static void Command(string[] args)
        {
            if ((args.Length > 0) && (Regex.Match(args[0], @"(-)?-help", RegexOptions.IgnoreCase).Success))
            {
                Console.WriteLine(help);
            }
            else
            {
                string[] commandlist = clist.ToArray();
                Array.Sort(commandlist);
                string st = "";
                for (int i = 0; i < commandlist.Length; i++)
                    st = st + " " + commandlist[i];
                st = st.Trim();
                Console.ForegroundColor = ConsoleColor.Yellow;
                for (int i = 0; i < commandlist.Length; i++)
                {
                    if ((i % 4 == 0) && (i != 0)) Console.Write("\n");
                    Console.Write(commandlist[i] + "\t");
                    if ((i == (commandlist.Length - 1)) && (i % 4 != 1))
                        Console.Write("\n");
                }
                Console.ResetColor();
            }
        }
    }
}
